package com.itheima.mapper;

import com.itheima.pojo.EmpOrders;
import com.itheima.pojo.OrdersList;
import com.itheima.pojo.User;
import com.itheima.pojo.UserOrders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface EmpMapper {
    @Select("select *from emp where empName=#{name} and password=#{password}")
    public User Elogin(User user);
    @Select("select *from emp where empName=#{name} and password=#{password} and state='禁用'")
    public User stateCheck(User user);
    @Select("select orders.orderId,userName,foodOrder,address,remark,orderTime,orderState,empName from orders left join emporders on orders.orderId=emporders.orderId where orderState='等待骑手' or orderState='派送中' and empName=#{empName}")
    public List<OrdersList> eShowOrders(String empName);
    @Update("update orders set orderState='派送中' where orderId=#{orderId}")
    public void addOrders(Long orderId);
    @Insert("insert into emporders (orderId,empName) values (#{orderId},#{empName})")
    public void addEmpOrders(Long orderId,String empName);
    @Update("update orders set orderState='已送达' where orderId=#{orderId}")
    public void arrive(Long orderId);
    @Select("select count(*) from orders left join emporders on orders.orderId=emporders.orderId where empName=#{empName} and orderState='已送达'")
    public int conCount(String empName);

    @Select("select orders.orderId,foodOrder,remark,orderTime,userName,address,rate from orders left join emporders on orders.orderId=emporders.orderId where emporders.empName=#{empName} order by orders.orderId desc limit #{start},#{pageSize}")
    public List<EmpOrders> conPage(String empName, int start, int pageSize);
    @Select("select empId from emp where empName=#{empName} and password=#{oldPassword}")
    public Long findOldPassword(String oldPassword,String empName);

    @Update("update emp set password=#{newPassword} where password=#{oldPassword} and empName=#{empName}")
    public void eChangePassword(String oldPassword,String newPassword,String empName);
}
